package com.miku.blog.domain.pojo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.miku.blog.eume.HttpStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * @author shkstart
 * @create ${}YEAR-05-24 23:07
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseResult<T> implements Serializable {

    private Integer code;
    private String message;
    private boolean flag = false;
    private T data;

    public ResponseResult(HttpStatusEnum httpStatusEnum){
        this.code = httpStatusEnum.getCode();
        this.message = httpStatusEnum.getMsg();
    }

    public static ResponseResult ok(){
        ResponseResult responseResult = new ResponseResult(HttpStatusEnum.OK);
        return responseResult.setFlag(true);
    }

    public static ResponseResult error(){
        ResponseResult responseResult = new ResponseResult(HttpStatusEnum.SYSTEM_ERROR);
        return responseResult;
    }


}
